package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeVipLevelListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewRechargeVipLevelListLogic VIP充值等级--列表
func NewRechargeVipLevelListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeVipLevelListLogic {
	return &RechargeVipLevelListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RechargeVipLevelListLogic) RechargeVipLevelList() (resp *types.RechargeVipLevelListResponse, err error) {
	rpcReq := rpc.RechargeVipLevelListRequest{}

	rpcResp, err := l.svcCtx.AssetsRpc.PayRecharge.RechargeVipLevelList(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}

	records := make([]types.VipLevel, len(rpcResp.Records))
	for i, r := range rpcResp.Records {
		records[i] = types.VipLevel{
			Id:     r.Id,
			Level:  r.Level,
			Times:  r.Times,
			Amount: r.Amount,
		}
	}

	return &types.RechargeVipLevelListResponse{
		Records: records,
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
